/*
 * This file is part of Space Invaders: Rehash
 * Copyright (C)2007 Vicent Marti (tanoku@gmail.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef __SPRITES_H__
#define __SPRITES_H__

#include "timer.h"

void glDrawSprite2D( GLuint sprite, int id, int rows, int cols, int x, int y, 
					float size, float rotation = 0.0f, float r = 1.0f, 
					float g = 1.0f, float b = 1.0f, float a = 1.0f);

class Sprite
{
protected:
	int m_sprite;
	int m_rows, m_cols;
	
	
	int m_x, m_y;
	int m_size;
	int m_timeToLive;
	
	SimpleTimer m_lifeTimer;
	
	int m_currentFrame;
	int m_maxFrames;
	
	bool m_dead;

public:
	Sprite( int sprite, int maxframes, int rows, int cols, 
		int x, int y, int size, int time )
	{
		m_sprite = sprite;
		m_rows = rows;
		m_cols = cols;
		m_x = x;
		m_y = y;
		m_timeToLive = time;
		m_maxFrames = maxframes;
		m_currentFrame = 0;
		m_dead = false;
		m_size = size;
		
		m_lifeTimer.start();
	}

	virtual ~Sprite() {}
	virtual void render() = 0;

	bool isDead()
	{
		return m_dead;
	}
	
	void update( int x, int y )
	{
		m_x = x;
		m_y = y;
	}
	
	void reset()
	{
		m_dead = false;
		m_lifeTimer.start();
	}
};

class Smoke : public Sprite
{
protected:
	bool m_fadeOut;

public:
	Smoke( int sprite, int maxframes, int rows, int cols, 
		int x, int y, int size, int time, bool fadeOut = false ) :
	Sprite( sprite, maxframes, rows, cols, x, y, size, time )
	{
		m_fadeOut = fadeOut;
	}

	void render();
};

class SmokeTrail : public Sprite
{
protected:
	Smoke *m_puffs[4];
	SimpleTimer m_puffTimer;
	
public:
	SmokeTrail( int x, int y, int time ) :
	Sprite( 0, 0, 0, 0, x, y, 0, time )
	{
		for ( int i=0; i<4; ++i )
		{
			m_puffs[i] = new Smoke( 7, 14, 4, 4, m_x, m_y, 32, 250, true); //new Smoke( 7, 14, 4, 4, m_x, m_y, 32, 750, true);
		}
		m_puffTimer.start();
	}

	void render();
};


class Explosion : public Sprite
{
protected:


public:
	Explosion( int sprite, int maxframes, int rows, int cols, 
		int x, int y, int size, int time ) :
	Sprite( sprite, maxframes, rows, cols, x, y, size, time )
	{
	}
	
	void render();
};

#endif


